﻿using System;
using System.ComponentModel;

namespace Orktane.ScriptActionModel
{
    public class ScriptActionInfo
        : INotifyPropertyChanged, IEquatable<ScriptActionInfo>
    {

        readonly Guid _id;
        readonly ScriptActionMeta _scriptActionMeta;
        readonly bool _isConsoleScript;

        public ScriptActionInfo(Guid id, ScriptActionMeta scriptActionMeta)
        {
            // basic checks
            if (Guid.Empty.Equals(id)) throw new ArgumentException("id");
            if (scriptActionMeta == null) throw new ArgumentNullException("scriptActionMeta");

            _id = id;
            _scriptActionMeta = scriptActionMeta;
            _isConsoleScript = typeof (IConsoleScriptAction).IsAssignableFrom(scriptActionMeta.ImplementationType);
        }

#region Properties

        public Guid Id 
        {
            get { return _id; } 
        }

        public ScriptActionMeta ScriptActionMeta
        {
            get { return _scriptActionMeta; }
        }

        public bool IsConsoleScript
        {
            get { return _isConsoleScript; }
        }

#endregion

#region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;

#endregion

#region IEquatable<ApplicationInfo> Members

        public bool Equals(ScriptActionInfo other)
        {
            if (other == null) return false;
            return other.ScriptActionMeta.ImplementationType.Equals(ScriptActionMeta.ImplementationType);
        }

#endregion

    }
}
